<?php

namespace App\Http\Controllers\Admin;

use App\Model\Ereason;
use App\Model\Examine;
use App\Model\Hreason;
use App\Model\Secify;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ExamineController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $item = Examine::where('state',0)->orderBy('id','desc')->paginate(15);
        $category = Secify::get();
        return view('admin.place.place-examine-list',compact('item','category'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $val = $request->input('data');
        $hid = $request->input('eid');
        $data = Ereason::create(['eid'=>$hid,'reason'=>$val]);
        if ($data){
            return $this->success('提交成功');
        }else {
            return $this->error('提交失败');
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $item = Examine::where('id',$id)->first();
        $category = Secify::get();
        return view('admin.place.place-examine-show',compact('item','category'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
//        return view('admin.place.place-examine-show');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update($id)
    {
        $m = Examine::find($id);
        $m->state = 1;
        if ($m->save()){
            return $this->success('操作成功');
        }else {
            return $this->error('操作失败');
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $data = Examine::where('id',$id)->delete();
        if ($data){
            return $this->success('删除成功');
        }else {
            return $this->error('删除失败');
        }
    }
}
